<template>
	<view class="withdraw">
		<view class="box">
			<view class="bankselect">
				<text>提现至</text>
				<view class="bankName" @tap="goCardList">
					{{bankName + bankType}}（{{bankNum.substring(bankNum.length-4)}}）
					<image src="../../static/images/arrows-right.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="money">
				<view class="title">
					提现金额
				</view>
				<view class="inputBox">
					￥<input  type="digit" v-model="money" />
				</view>
				
			</view>
			<view class="getAll">
				<text>当前余额{{allMoney}}元</text>
				<text class="getAllBtn" @tap="getAll">全部提现</text>
			</view>
			<view class="submit" @tap="submit">
				确认提现
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				money:"",
				allMoney:0,
				bankName:"",
				bankType:"",
				bankNum:"",
				user:"",
				cardId:""
			}
		},
		onLoad() {
			this.getAllMoney()
			this.getBankCard()
		},
		onShow() {
			let _this = this;
			uni.$once('selectBankCard',function(data){
				_this.bankName = data.bank
				_this.bankType = data.cardType
				_this.bankNum = data.bankCard
				_this.user = data.bankUserName;
				_this.cardId = data.id
			})
			
		},
		methods:{
			getAll(){
				this.money = this.allMoney
			},
			goCardList(){
				uni.navigateTo({
					url:'../bank/bankCardList?isWithdtaw=1'
				})
			},
			getAllMoney(){
				let data = {
					accountId:uni.getStorageSync("buyerAccountId")
				}
				this.$http.post('/api/v1.0/user/findUserProperty',data,res=>{
					this.allMoney = res.data.data.money;
				})
			},
			getBankCard(){
				let data = {
					accountId:uni.getStorageSync("buyerAccountId")
				}
				this.$http.post('/api/v1.0/user/queryAccountIsExtBankByAccountId',data,res=>{
					this.cardId = res.data.data.list[0].id
					this.bankName = res.data.data.list[0].bank;
					this.bankType = res.data.data.list[0].cardType;
					this.bankNum = res.data.data.list[0].bankCard;
					this.user = res.data.data.list[0].bankUserName;
				})
			},
			//提现
			submit(){
				if(this.money == ""){
					return
				}
				if(this.money > this.allMoney){
						uni.showToast({
							title:"余额不足",
							icon:"none"
						})
					return
				}else{
					let data = {
						accountId:uni.getStorageSync("buyerAccountId"),
						bank:this.bankNamem,
						bankCard:this.bankNum,
						bankUserName:this.user,
						money:this.money,
						accountExtBankId:this.cardId
					}
					this.$http.post('/api/v1.0/user/createUserWithdrawal',data,res=>{
						if(res.data.status == '000000'){
							uni.showToast({
								title:"提现申请已提交，请耐心等待",
								icon:'none'
							})
							setTimeout(()=>{
								uni.navigateBack()
							},1000)
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none"
							})
						}
					})
				}
			},
			
		}
	}
</script>

<style lang="scss">
	.withdraw{
		background-color: #f2f2f2;
		min-height: 100vh;
		padding: 30upx 28upx 0;
		box-sizing: border-box;
		.box{
			background-color: #fff;
			border-radius: 20upx;
			padding: 40upx;
			box-sizing: border-box;
			.bankselect{
				display: flex;
				justify-content: space-between;
				font-size: 28upx;
				border-bottom: 1upx solid #f2f2f2;
				padding-bottom: 20upx;
				text{
					color: #999999;
				}
				.bankName{
					color: #333;
					
					image{
						width: 22upx;
						height: 22upx;
					}
				}
			}
			.money{
				margin-top: 50upx;
				.title{
					font-size: 32upx;
					color: #4d4d4d;
				}
				.inputBox{
					font-size: 60upx;
					color: #333;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					border-bottom: 1upx solid #f2f2f2;
					input{
						font-size: 60upx;
						height: 70upx;
						margin-left: 20upx;
					}
				}
			}
			.getAll{
				font-size: 28upx;
				color: #999;
				display: flex;
				justify-content: space-between;
				margin-top: 20upx;
				.getAllBtn{
					color: #E54639;
				}
			}
			.submit{
				width:616upx;
				height:104upx;
				background:linear-gradient(0deg,rgba(227,67,57,1),rgba(249,98,58,1));
				border-radius:20upx;
				color: #fff;
				font-size: 40upx;
				margin-top: 70upx;
				text-align: center;
				line-height: 104upx;
			}
		}
	}
</style>
